import java.util.Scanner;
public class Main {
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String s1=scanner.next();
            String s2=scanner.next();
            String Long=s1.length()>s2.length()?s1:s2;
            String Short=s1.length()<s2.length()?s1:s2;
            int max=0;
            String ret="";
            for(int i=0;i<Short.length();i++){
                for(int j=i+1;j<=Short.length();j++){
                    if(Long.contains(Short.substring(i,j))&&(j-i)>max){
                        max=j-i;
                        ret=Short.substring(i,j);
                    }
                }
            }
            System.out.println(ret);
        }
    }
}














//public class Main {
//    public static void main(String[] args) {
//        Scanner scanner=new Scanner(System.in);
//        while (scanner.hasNext()){
//            int n=scanner.nextInt();
//            if(n==0){
//                return;
//            }
//            System.out.println(n/2);
//        }
//    }
//}
